package vote

import (
	"HeadLineNews/resp"
	"github.com/gin-gonic/gin"
)

type Server interface {
	UserVoteHandler(c *gin.Context)
}

type server struct {
	ctx   Ctx
	cache Cache
}

func NewServer() Server {
	return &server{ctx: NewCtx(), cache: NewCache()}
}

// UserVoteHandler 用户点赞
func (s *server) UserVoteHandler(c *gin.Context) {
	p, err := s.ctx.ParseParamUserVote(c)
	if err != nil {
		return
	}
	if err = s.cache.UserVote(c, p); err != nil {
		return
	}
	resp.Success(c, nil)
}
